package com.ymatou.iapi.godmch.testcase;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.createagentBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.service.createagentCall;
import com.ymatou.iapi.godmch.service.createmchCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.agent_type;
import com.ymttest.database.model.invite_code;
import com.ymttest.database.sqlwapper.godmch.agent_typeWapper;
import com.ymttest.database.sqlwapper.godmch.invite_codeWapper;
import com.ymttest.utils.TestDataManager;

/**
 * 新增代理类型 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_CreateAgentType {
	private static createagentBean bean;
	private static createagentCall call;
	private createmchBean createmchbean = new createmchBean();
	private createmchCall createmchcall = new createmchCall();
	public agent_typeWapper agentTypeWapper = new agent_typeWapper();
	private invite_codeWapper inviteCodeWapper = new invite_codeWapper();

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("新增代理类型");
	}

	@Before
	public void caseUp() {
		bean = new createagentBean();
		call = new createagentCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateAgentType_001() {
		Logger.start(true, "新增代理类型,验证商户id存在-代理类型标题满足条件");
		try {
			// 新增渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			int userId = createmchbean.getMchId();

			bean.setMchId(userId);
			bean.setTitle("测试代理标题_" + TestDataManager.getRandomIntNum(5));
			bean.setRemark("测试代理备注_" + TestDataManager.getRandomIntNum(5));
			bean.setDiscount(new BigDecimal(8));//折扣
			call.setData(bean);
			call.callService();
			// 断言
			checkVerify(userId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateAgentType_001_1() {
		Logger.start(true, "新增代理类型,验证discount为小数");
		try {
			// 新增渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			int userId = createmchbean.getMchId();

			bean.setMchId(userId);
			bean.setTitle("测试代理标题_" + TestDataManager.getRandomIntNum(5));
			bean.setRemark("测试代理备注_" + TestDataManager.getRandomIntNum(5));
			bean.setDiscount(new BigDecimal("8.23"));//折扣
			call.setData(bean);
			call.callService();
			// 断言
			checkVerify(userId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateAgentType_002() {
		Logger.start(true, "新增代理类型,验证商户id不存在-代理类型标题满足条件,返回错误");
		try {
			// 新增渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			int userId = createmchbean.getMchId();

			bean.setMchId(userId + 1);
			bean.setTitle("测试代理标题_" + TestDataManager.getRandomIntNum(5));
			bean.setRemark("测试代理备注_" + TestDataManager.getRandomIntNum(5));
			bean.setDiscount(new BigDecimal(8));//折扣
			call.setData(bean);
			call.callService();
			// 断言
			Logger.verifyEquals("5004", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals("商户不存在", call.getMessage(), "验证返回成功Message值");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateAgentType_003() {
		Logger.start(true, "新增代理类型,验证商户id存在-代理类型标题等于8个汉字,返回正确");
		try {
			// 新增渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			int userId = createmchbean.getMchId();

			bean.setMchId(userId);
			bean.setTitle("测试代理测试代理");
			bean.setRemark("测试代理备注_" + TestDataManager.getRandomIntNum(5));
			bean.setDiscount(new BigDecimal(8));//折扣
			call.setData(bean);
			call.callService();
			// 断言
			checkVerify(userId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateAgentType_003_1() {
		Logger.start(true, "新增代理类型,验证商户id存在-代理类型标题超过了8个汉字,返回错误");
		try {
			// 新增渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			int userId = createmchbean.getMchId();

			bean.setMchId(userId);
			bean.setTitle("测试代理标代理标1");
			bean.setRemark("测试代理备注_" + TestDataManager.getRandomIntNum(5));
			bean.setDiscount(new BigDecimal(8));//折扣
			call.setData(bean);
			call.callService();
			// 断言
			Logger.verifyEquals("5003", call.getStatusCode1(), "验证返回成功status值");
//			Logger.verifyEquals(true, call.getMessage().contains("代理类型标题8个汉字或16个英文"), "验证返回成功Message值");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateAgentType_004() {
		Logger.start(true, "新增代理类型,验证商户id存在-代理类型标题等于24个英文,返回正确");
		try {
			// 新增渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			int userId = createmchbean.getMchId();

			bean.setMchId(userId);
			bean.setTitle("abcdefghlmabcdefghlmabcd");
			// bean.setRemark("123456789012345678901234");
			bean.setRemark("测试代理备注_" + TestDataManager.getRandomIntNum(5));
			bean.setDiscount(new BigDecimal(8));//折扣
			call.setData(bean);
			call.callService();
			// 断言
			checkVerify(userId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateAgentType_004_1() {
		Logger.start(true, "新增代理类型,验证商户id存在-代理类型标题超过了24个英文,返回错误");
		try {
			// 新增渠道商
			// 新增渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			int userId = createmchbean.getMchId();

			bean.setMchId(userId);
			bean.setTitle("abcdefghlmabcdefghlmabcde");
			bean.setRemark("测试代理备注_" + TestDataManager.getRandomIntNum(5));
			bean.setDiscount(new BigDecimal(8));//折扣
			call.setData(bean);
			call.callService();
			// 断言
			Logger.verifyEquals("5003", call.getStatusCode1(), "验证返回成功status值");
//			Logger.verifyEquals(true, call.getMessage().contains("代理类型标题8个汉字或16个英文"), "验证返回成功Message值");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateAgentType_005() {
		Logger.start(true, "新增代理类型,验证商户id存在-代理类型标题重复,返回错误");
		try {
			// 新增渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			int userId = createmchbean.getMchId();

			bean.setMchId(userId);
			bean.setTitle("测试代理标题");
			bean.setRemark("测试代理备注_" + TestDataManager.getRandomIntNum(5));
			bean.setDiscount(new BigDecimal(8));//折扣
			call.setData(bean);
			call.callService();
			call.callService();
			// 断言
			Logger.verifyEquals("5006", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals(true, call.getMessage().contains("代理类型标题重复"), "验证返回成功Message值");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	//创建的时候会默认插入一个一级代理所以只可自建2个
	public void Tc_CreateAgentType_006() {
		Logger.start(true, "新增代理类型,验证商户id存在-代理类型总个数等于配置的数量(目前是配置3个),返回错误");
		try {
			// 新增渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			int userId = createmchbean.getMchId();

			bean.setMchId(userId);
			String title1 = "测试代理标题_" + TestDataManager.getRandomIntNum(5);
			bean.setTitle(title1);
			bean.setRemark("测试代理备注_" + TestDataManager.getRandomIntNum(5));
			bean.setDiscount(new BigDecimal(8));//折扣
			call.setData(bean);
			call.callService();
			String title2 = "测试代理标题_" + TestDataManager.getRandomIntNum(5);
			bean.setTitle(title2);
			bean.setDiscount(new BigDecimal(8));//折扣
			call.setData(bean);
			call.callService();
//			String title3 = "测试代理标题_" + TestDataManager.getRandomIntNum(5);
//			bean.setTitle(title3);
//			call.setData(bean);
//			call.callService();
			// 断言
			// 获取代理
			Map<String, Object> map = new HashMap();
			map.put("mchId", userId);
			List<agent_type> list = agentTypeWapper.selectby(map);
			// 验证点
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
			Logger.verifyEquals(true, call.getSuccess(), "验证返回成功Success值");
			int count = 0;
			for (agent_type type : list) {
				count++;
				if (type.getTypeTitle().equals(bean.getTitle())) {
					Logger.verifyEquals(bean.getMchId(), type.getMchId(), "验证第" + count + "个代理商 ,数据表agent_type中的字段MchId");
					Logger.verifyEquals(bean.getTitle(), type.getTypeTitle(), "验证第" + count + "个代理商 ,数据表agent_type中的字段TypeTitle");
					Logger.verifyEquals(bean.getRemark(), type.getRemark(), "验证第" + count + "个代理商 ,数据表agent_type中的字段Remark");
					Logger.verifyEquals(0, type.getState(), "验证第" + count + "个代理商 ,数据表agent_type中的字段State");
					Logger.verifyNotNull(type.getCreateTime(), "验证第" + count + "个代理商 ,数据表agent_type中的字段CreateTime");
					Logger.verifyNotNull(type.getUpdateTime(), "验证第" + count + "个代理商 ,数据表agent_type中的字段UpdateTime");
					Logger.verifyEquals(bean.getDiscount().stripTrailingZeros().toPlainString(), type.getDiscount().stripTrailingZeros().toPlainString(), "验证第" + count + "个代理商 ,数据表agent_type中的字段discount");
				}
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateAgentType_006_1() {
		Logger.start(true, "新增代理类型,验证商户id存在-代理类型总个数超过了配置的数量(目前是配置3个),返回错误");
		try {
			// 新增渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			int userId = createmchbean.getMchId();

			bean.setMchId(userId);
			bean.setTitle("测试代理标题_" + TestDataManager.getRandomIntNum(5));
			bean.setRemark("测试代理备注_" + TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();
			bean.setTitle("测试代理标题_" + TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();
			bean.setTitle("测试代理标题_" + TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();

			bean.setTitle("测试代理标题_" + TestDataManager.getRandomIntNum(5));
			call.setData(bean);
			call.callService();
			// 断言
			Logger.verifyEquals("5005", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals(true, call.getMessage().contains("代理类型最多创建3个"), "验证返回成功Message值");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateAgentType_007() {
		Logger.start(true, "新增代理类型,验证discount 为空,数据库为0");
		try {
			// 新增渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			int userId = createmchbean.getMchId();

			bean.setMchId(userId);
			bean.setTitle("测试代理标题_" + TestDataManager.getRandomIntNum(5));
			bean.setRemark("测试代理备注_" + TestDataManager.getRandomIntNum(5));
			//bean.setDiscount(new BigDecimal(8));//折扣
			call.setData(bean);
			call.callService();
			// 断言
			// 获取代理
			Map<String, Object> map = new HashMap();
			map.put("mchId", userId);
			List<agent_type> list = agentTypeWapper.selectby(map);
			// 验证点
			Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
			Logger.verifyEquals(true, call.getSuccess(), "验证返回成功Success值");
			int count = 0;
			for (agent_type type : list) {
				count++;
				if (type.getTypeTitle().equals(bean.getTitle())) {
					Logger.verifyEquals(bean.getMchId(), type.getMchId(), "验证第" + count + "个代理商 ,数据表agent_type中的字段MchId");
					Logger.verifyEquals(bean.getTitle(), type.getTypeTitle(), "验证第" + count + "个代理商 ,数据表agent_type中的字段TypeTitle");
					Logger.verifyEquals(bean.getRemark(), type.getRemark(), "验证第" + count + "个代理商 ,数据表agent_type中的字段Remark");
					Logger.verifyEquals(0, type.getState(), "验证第" + count + "个代理商 ,数据表agent_type中的字段State");
					Logger.verifyNotNull(type.getCreateTime(), "验证第" + count + "个代理商 ,数据表agent_type中的字段CreateTime");
					Logger.verifyNotNull(type.getUpdateTime(), "验证第" + count + "个代理商 ,数据表agent_type中的字段UpdateTime");
					Logger.verifyEquals("0", type.getDiscount().stripTrailingZeros().toPlainString(), "验证第" + count + "个代理商 ,数据表agent_type中的字段discount");
				}
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
    //////////////////// 20200513新增////////////////////
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateAgentType_008() {
		Logger.start(true, "新增代理类型,验证RebateRate不等于0返佣,agentMode=2自动继承（分销小店）,返回成功");
		try {
			// 新增渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			int userId = createmchbean.getMchId();

			bean.setMchId(userId);
			bean.setTitle("测试代理标题_" + TestDataManager.getRandomIntNum(5));
			bean.setRemark("测试代理备注_" + TestDataManager.getRandomIntNum(5));
			bean.setDiscount(new BigDecimal(8));//折扣
			
			bean.setRebateRate(new BigDecimal(1));
			bean.setAgentMode(2);
			call.setData(bean);
			call.callService();
			// 断言
			checkVerify(userId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateAgentType_009() {
		Logger.start(true, "新增代理类型,验证RebateRate等于0返佣,agentMode=2自动继承（分销小店),返回成功");
		try {
			// 新增渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			int userId = createmchbean.getMchId();

			bean.setMchId(userId);
			bean.setTitle("测试代理标题_" + TestDataManager.getRandomIntNum(5));
			bean.setRemark("测试代理备注_" + TestDataManager.getRandomIntNum(5));
			bean.setDiscount(new BigDecimal(8));//折扣
			
			bean.setRebateRate(new BigDecimal(1));
			bean.setAgentMode(2);
			call.setData(bean);
			call.callService();
			// 断言
			checkVerify(userId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateAgentType_010() {
		Logger.start(true, "新增代理类型,验证RebateRate等于1返佣,agentMode=1自主选货（分销代理）,返回数据库中RebateRate=0");
		//如果agentMode=1 - 自主选货（分销代理）,rebateRate返佣比例不管是什么值,都为0
		try {
			// 新增渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			int userId = createmchbean.getMchId();

			bean.setMchId(userId);
			bean.setTitle("测试代理标题_" + TestDataManager.getRandomIntNum(5));
			bean.setRemark("测试代理备注_" + TestDataManager.getRandomIntNum(5));
			bean.setDiscount(new BigDecimal(8));//折扣
			
			bean.setRebateRate(new BigDecimal(1));
			bean.setAgentMode(1);
			call.setData(bean);
			call.callService();
			// 断言
			checkVerify(userId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateAgentType_0011() {
		Logger.start(true, "新增代理类型,验证DB自主选货=3,DB自动继承=0,创建自动继承成功(目前是各自配置3个)");
		try {
			// 新增渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			int userId = createmchbean.getMchId();

			bean.setDiscount(new BigDecimal(1));
			bean.setMchId(userId);
			bean.setTitle("自主选货标题_" + TestDataManager.getRandomIntNum(2));
			bean.setRemark("自主选货备注_" + TestDataManager.getRandomIntNum(2));
			call.setData(bean);
			call.callService();
			bean.setTitle("自主选货标题_" + TestDataManager.getRandomIntNum(2));
			call.setData(bean);
			call.callService();

			bean.setTitle("自动继承标题_" + TestDataManager.getRandomIntNum(2));
			bean.setRemark("自动继承备注_" + TestDataManager.getRandomIntNum(2));
			bean.setAgentMode(2);//代理模式 1 - 自主选货（分销代理） 2 - 自动继承（分销小店）
			bean.setRebateRate(new BigDecimal(1));//返佣比例，agentMode = 分销小店有效，其它场景设置为 0
			call.setData(bean);
			call.callService();
			// 断言
			checkVerify(userId);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateAgentType_0012() {
		Logger.start(true, "新增代理类型,验证DB自主选货=3,DB自动继承=3,创建自动继承失败(目前是各自配置3个)-返回失败");
		try {
			// 新增渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			int userId = createmchbean.getMchId();
			bean.setMchId(userId);
			
			for(int i=0;i<2;i++)
			{
				bean.setDiscount(new BigDecimal(1));
				bean.setTitle("自主选货标题_" + TestDataManager.getRandomIntNum(2));
				bean.setRemark("自主选货备注_" + TestDataManager.getRandomIntNum(2));
				call.setData(bean);
				call.callService();
				bean.setTitle("自主选货标题_" + TestDataManager.getRandomIntNum(2));
				call.setData(bean);
				call.callService();
			}

			for(int i=0;i<4;i++)
			{
				bean.setTitle("自动继承标题_" + TestDataManager.getRandomIntNum(2));
				bean.setRemark("自动继承备注_" + TestDataManager.getRandomIntNum(2));
				bean.setAgentMode(2);//代理模式 1 - 自主选货（分销代理） 2 - 自动继承（分销小店）
				bean.setRebateRate(new BigDecimal(1));//返佣比例，agentMode = 分销小店有效，其它场景设置为 0
				call.setData(bean);
				call.callService();
			}
			
			// 断言
			Logger.verifyEquals("5005", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals(true, call.getMessage().contains("代理类型最多创建3个"), "验证返回成功Message值");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateAgentType_013() {
		Logger.start(true, "新增代理类型,验证DB自主选货=3,DB自动继承=3,创建自主选货失败(目前是各自配置3个)-返回失败");
		try {
			// 新增渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			int userId = createmchbean.getMchId();
			bean.setMchId(userId);
			
			for(int i=0;i<3;i++)
			{
				bean.setTitle("自动继承标题_" + TestDataManager.getRandomIntNum(2));
				bean.setRemark("自动继承备注_" + TestDataManager.getRandomIntNum(2));
				bean.setAgentMode(2);//代理模式 1 - 自主选货（分销代理） 2 - 自动继承（分销小店）
				bean.setRebateRate(new BigDecimal(1));//返佣比例，agentMode = 分销小店有效，其它场景设置为 0
				call.setData(bean);
				call.callService();
			}
			for(int i=0;i<3;i++)
			{
				bean.setDiscount(new BigDecimal(1));
				bean.setTitle("自主选货标题_" + TestDataManager.getRandomIntNum(2));
				bean.setRemark("自主选货备注_" + TestDataManager.getRandomIntNum(2));
				call.setData(bean);
				call.callService();
				bean.setTitle("自主选货标题_" + TestDataManager.getRandomIntNum(2));
				call.setData(bean);
				call.callService();
			}
			// 断言
			Logger.verifyEquals("5005", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals(true, call.getMessage().contains("代理类型最多创建3个"), "验证返回成功Message值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateAgentType_014() {
		Logger.start(true, "新增代理类型,验证DB自动继承=3,创建自继承货失败(目前是各自配置3个)-返回失败");
		try {
			// 新增渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			int userId = createmchbean.getMchId();
			bean.setMchId(userId);
			
			for(int i=0;i<3;i++)
			{
				bean.setTitle("自动继承标题_" + TestDataManager.getRandomIntNum(2));
				bean.setRemark("自动继承备注_" + TestDataManager.getRandomIntNum(2));
				bean.setAgentMode(2);//代理模式 1 - 自主选货（分销代理） 2 - 自动继承（分销小店）
				bean.setRebateRate(new BigDecimal(1));//返佣比例，agentMode = 分销小店有效，其它场景设置为 0
				call.setData(bean);
				call.callService();
			}
			call.setData(bean);
			call.callService();
			
			// 断言
			Logger.verifyEquals("5005", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals(true, call.getMessage().contains("代理类型最多创建3个"), "验证返回成功Message值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
		
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateAgentType_015() {
		Logger.start(true, "新增代理类型,验证rebateRate=50-返回失败,rebateRate <= 50");
		try {
			// 新增渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			int userId = createmchbean.getMchId();
			bean.setMchId(userId);
			
			bean.setTitle("自动继承标题_" + TestDataManager.getRandomIntNum(5));
			bean.setRemark("自动继承备注_" + TestDataManager.getRandomIntNum(5));
			bean.setAgentMode(2);//代理模式 1 - 自主选货（分销代理） 2 - 自动继承（分销小店）
			bean.setRebateRate(new BigDecimal(50));//返佣比例，rebateRate < 50
			call.setData(bean);
			call.callService();

			// 断言
			checkVerify(userId);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CreateAgentType_016() {
		Logger.start(true, "新增代理类型,验证rebateRate=51-返回失败,rebateRate <= 50");
		try {
			// 新增渠道商
			createmchBean createmchbean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchbean);
			int userId = createmchbean.getMchId();
			bean.setMchId(userId);
			
			bean.setTitle("自动继承标题_" + TestDataManager.getRandomIntNum(5));
			bean.setRemark("自动继承备注_" + TestDataManager.getRandomIntNum(5));
			bean.setAgentMode(2);//代理模式 1 - 自主选货（分销代理） 2 - 自动继承（分销小店）
			bean.setRebateRate(new BigDecimal(51));//返佣比例，rebateRate < 50
			call.setData(bean);
			call.callService();

			// 断言
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证返回成功status值");
			Logger.verifyEquals(true, call.getMessage().contains("rebateRate <= 50"), "验证返回成功Message值");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	private void checkVerify(int mchId) throws InterruptedException, JSONException {
		// 获取代理
		Map<String, Object> map = new HashMap();
		map.put("mchId", mchId);
		List<agent_type> list = agentTypeWapper.selectby(map);
		// 验证点
		Logger.verifyEquals("200", call.getStatusCode1(), "验证返回成功status值");
		Logger.verifyEquals("请求成功", call.getMessage(), "验证返回成功Message值");
		Logger.verifyEquals(true, call.getSuccess(), "验证返回成功Success值");
		int count = 0;
		for (agent_type type : list) {
			if (type.getTypeTitle().equals(bean.getTitle())) {
				Logger.verifyEquals(bean.getMchId(), type.getMchId(), "验证第" + count + "个代理商 ,数据表agent_type中的字段MchId");
				Logger.verifyEquals(bean.getTitle(), type.getTypeTitle(), "验证第" + count + "个代理商 ,数据表agent_type中的字段TypeTitle");
				Logger.verifyEquals(bean.getRemark(), type.getRemark(), "验证第" + count + "个代理商 ,数据表agent_type中的字段Remark");
				Logger.verifyEquals(0, type.getState(), "验证第" + count + "个代理商 ,数据表agent_type中的字段State");
				Logger.verifyNotNull(type.getCreateTime(), "验证第" + count + "个代理商 ,数据表agent_type中的字段CreateTime");
				Logger.verifyNotNull(type.getUpdateTime(), "验证第" + count + "个代理商 ,数据表agent_type中的字段UpdateTime");
				if(bean.getDiscount()==null)
					Logger.verifyEquals("0", type.getDiscount().stripTrailingZeros().toPlainString(), "验证第" + count + "个代理商 ,数据表agent_type中的字段discount");
				else
				    Logger.verifyEquals(bean.getDiscount().stripTrailingZeros().toPlainString(), type.getDiscount().stripTrailingZeros().toPlainString(), "验证第" + count + "个代理商 ,数据表agent_type中的字段discount");
				
				if(bean.getAgentMode()!=null && bean.getRebateRate()!=null){
				   //如果agentMode=1 - 自主选货（分销代理）,rebateRate返佣比例不管是什么值,都为0
				   Logger.verifyEquals(bean.getAgentMode()==2?bean.getRebateRate().stripTrailingZeros().toPlainString():"0", type.getRebateRate().stripTrailingZeros().toPlainString(), "验证第" + count + "个代理商 ,数据表agent_type中的字段RebateRate");
				   Logger.verifyEquals(bean.getAgentMode(), type.getAgentMode(), "验证第" + count + "个代理商 ,数据表agent_type中的字段AgentMode");
				}
			}
		}
	}
}